package com.fortune.controller;

import java.util.List;

import com.fortune.base.BaseController;
import com.fortune.dto.excution.DriverReturnDepositExcution;
import com.fortune.enums.DriverReturnDepositEnum;
import com.fortune.service.DriverReturnDepositService;
import com.fortune.vo.cReturnDeposit.CReturnDepositDetail;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fortune.base.BaseAPIExcution;
import com.fortune.vo.driverReturnDeposit.DriverReturnDepositDetail;
import com.fortune.vo.driverReturnDeposit.DriverReturnDepositInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "wechat/driverReturnDeposit", description = "退押金工单", tags = {"微信小程序（司机）：退押金工单"})
@RestController
@RequestMapping("wechat/driverReturnDeposit")
public class DriverReturnDepositController extends BaseController{
	@Autowired
	private DriverReturnDepositService driverReturnDepositService;

	@ApiOperation(value = "退押金工单列表", nickname = "driverReturnDepositList", notes = "", tags = {"@郭阳"})
	@ApiImplicitParams({
			@ApiImplicitParam(name="Authorization", value="登录返回的token值",paramType="header",dataType="String",required = true)
	})
    @GetMapping(value = "list",
        produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<List<DriverReturnDepositInfo>> list() {
		String mid = getMId();
		String did = getDId();
		String id = getUserId();
		List<DriverReturnDepositInfo> list = driverReturnDepositService.findDriverReturnDepositList(mid,did,id);
		if(list.size() == 0){
			return new DriverReturnDepositExcution<List<DriverReturnDepositInfo>>(list, DriverReturnDepositEnum.SUCCESS);
		}
		String box;
		String allow;
		String returns;
		String account;
		for (int i=0; i<list.size();i++){
			DriverReturnDepositInfo driverReturnDepositInfo = list.get(i);
			 box = driverReturnDepositInfo.getBoxIsIn().toString();
			 allow = driverReturnDepositInfo.getIsAllow().toString();
			 returns = driverReturnDepositInfo.getIsReturn().toString();
			 account = driverReturnDepositInfo.getIsAccount().toString();
			 if(box.equals("YES")&&allow.equals("YES")&&returns.equals("YES")&&account.equals("YES")){
			 	driverReturnDepositInfo.setType(1);
			 }else if(box.equals("NO")&&allow.equals("YES")&&returns.equals("NO")&&account.equals("NO")){
			 	driverReturnDepositInfo.setType(2);
			 }else if(box.equals("NO")&&allow.equals("NO")&&returns.equals("NO")&&account.equals("NO")){
			 	driverReturnDepositInfo.setType(3);
			 }else{
				 driverReturnDepositInfo.setType(4);
			 }
		}
		return new DriverReturnDepositExcution<List<DriverReturnDepositInfo>>(list, DriverReturnDepositEnum.SUCCESS);
	}
	
	@ApiOperation(value = "退押金工单详情", nickname = "driverReturnDepositDetail", notes = "", tags = {"@郭阳"})
	@ApiImplicitParams({
		@ApiImplicitParam(name="id", value="订单id",paramType="query",dataType="string"),
		@ApiImplicitParam(name="clientId", value="客户id",paramType="query",dataType="string"),
		@ApiImplicitParam(name="Authorization", value="登录返回的token值",paramType="header",dataType="String",required = true)
	})
    @GetMapping(value = "detail",
        produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<DriverReturnDepositDetail> detail(@Validated @NotBlank(message="订单id不能为空") String id,
			@Validated @NotBlank(message="客户id不能为空") String clientId) {
		String mid = getMId();
		String did = getDId();
		DriverReturnDepositDetail driverReturnDepositDetail = driverReturnDepositService.findDriverReturnDepositDetail(id,clientId,mid,did);
		 return new DriverReturnDepositExcution<DriverReturnDepositDetail>(driverReturnDepositDetail,DriverReturnDepositEnum.SUCCESS);
	}
}
